const utils = require('../../../components/common/utils/utils.js');
import tui from '../../../common/httpRequest'
Page({
  data: {
    type: 1,
    status: [],
    arrowType: 1,
    minDate: "1920-01-01",
    maxDate: "",
    btnType: "primary",
    activeBgColor: "#5677fc",
    rangeBgColor: "rgba(86,119,252,0.1)",
    rangeColor: "#5677fc",
    startText: "开始",
    endText: "结束",
    lunar: true,
    result: "",
    lunarResult: "",
    initStartDate: '',
    initEndDate: ''
  },
  switchChange(e) {
    this.setData({
      lunar: e.detail.value
    })
  },
  selectDate(e) {
    let type = Number(e.currentTarget.dataset.type)
    this.setData({
      arrowType: 1,
      minDate: "1920-01-01",
      maxDate: "",
      btnType: "primary",
      activeBgColor: "#5677fc",
      rangeBgColor: "rgba(86,119,252,0.1)",
      rangeColor: "#5677fc",
      startText: "开始",
      endText: "结束",
      initStartDate: '',
      initEndDate: ''
    })
    switch (type) {
      case 1:
        this.setData({
          type: 1
        })
        break;
      case 2:
        this.setData({
          type: 2
        })
        break;
      case 3:
        this.setData({
          minDate: "2020-04-01",
          maxDate: "2021-06-08",
          type: 1
        })
        break;
      case 4:
        this.setData({
          type: 2,
          btnType: "danger",
          activeBgColor: "#EB0909",
          rangeBgColor: "rgba(235,9,9,0.1)",
          rangeColor: "#EB0909",
          arrowType: 1
        })
        break;
      case 5:
        this.setData({
          type: 2,
          startText: "住店",
          endText: "离店"
        })
        break;
      case 6:
        this.setData({
          arrowType: 2
        })
        break;
      case 7:
        this.setData({
          type: 2,
          initStartDate: '2020-06-06',
          initEndDate: '2020-06-28'
        })
        break;
      default:
        break;
    }
    setTimeout(() => {
      utils.calendar()
    }, 50)
  },
  change(event) {
    let e = event.detail
    console.log(e)
    if (this.data.type == 1) {
      let date = `${e.lunar.lYear}-${e.lunar.lMonth}-${e.lunar.lDay}`
      this.setData({
        result: e.result + " " + e.week,
        lunarResult: `${e.lunar.gzYear}年，${e.lunar.gzMonth}月，${e.lunar.gzDay}日 。生肖：${e.lunar.Animal}。日期：${e.lunar.IMonthCn + e.lunar.IDayCn}(${date})`
      })
    } else {
      let sDate = `${e.startLunar.IMonthCn + e.startLunar.IDayCn}(${e.startLunar.lYear}-${e.startLunar.lMonth}-${e.startLunar.lDay})`
      let eDate = `${e.endLunar.IMonthCn + e.endLunar.IDayCn}(${e.endLunar.lYear}-${e.endLunar.lMonth}-${e.endLunar.lDay})`
      this.setData({
        result: `${e.startDate} 至 ${e.endDate}`,
        lunarResult: `${sDate} 至 ${eDate}`
      })
    }
  },
  monthChange(e) {
    //  {
    // 	days: 31, //当月共有多少天
    // 	isToday: false, //是否为今天
    // 	result: "2020-05-04",
    // 	year: 2020
    // 	month: 5,
    // 	day: 4, 
    // 	week: "星期一"
    // }
    tui.toast(e.detail.result)
    if (e.detail.switch) {
      let now = new Date();
      let year = now.getFullYear();
      let month = now.getMonth() + 1;
      let day = now.getDate() - 1
      if (e.detail.year == year && e.detail.month == month) {
        let days = e.detail.days;
        let status = []
        for (let i = 0; i < days; i++) {
          let bgColor = "";
          let check = false;
          if (i <= day) {
            bgColor = i === day ? "#19be6b" : "#ff7900";
            check = i === day ? true : false;
          } else {
            bgColor = "#999";
          }
          status.push({
            bgColor: bgColor,
            color: "#fff",
            check: check
          })
        }
        this.setData({
          status: status
        })
      } else {
        this.setData({
          status: []
        })
      }
    }
  }
})